<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="linux,">










<meta name="description" content="yum 和 源码包 安装的 区别这里先说明下 yum 和 源码包 安装的 区别： yum 安装是在线安装，好处是：安装方式简单，不易出错；源码包 安装是先将 nginx 的源码下载下来，在自己的系统里编译生成可执行文件，然后执行，好处是：因为是在自己的系统上编译的，更符合自己系统的性能，也就是说在自己的系统上执行 nginx 服务性能效率更好。 安装路径不同他们之间最大的区别是 ：安装位置不同。">
<meta name="keywords" content="linux">
<meta property="og:type" content="article">
<meta property="og:title" content="centos安装nginx教程">
<meta property="og:url" content="https://blog.xiezc.xyz/2018/11/02/nginx_tomcat_jetty/centos安装nginx教程/index.html">
<meta property="og:site_name" content="xiezc的小站">
<meta property="og:description" content="yum 和 源码包 安装的 区别这里先说明下 yum 和 源码包 安装的 区别： yum 安装是在线安装，好处是：安装方式简单，不易出错；源码包 安装是先将 nginx 的源码下载下来，在自己的系统里编译生成可执行文件，然后执行，好处是：因为是在自己的系统上编译的，更符合自己系统的性能，也就是说在自己的系统上执行 nginx 服务性能效率更好。 安装路径不同他们之间最大的区别是 ：安装位置不同。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://segmentfault.com/img/bVD1yy?w=1316&h=440">
<meta property="og:image" content="https://segmentfault.com/img/bVD1yj?w=650&h=261">
<meta property="og:updated_time" content="2019-04-04T14:28:34.540Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="centos安装nginx教程">
<meta name="twitter:description" content="yum 和 源码包 安装的 区别这里先说明下 yum 和 源码包 安装的 区别： yum 安装是在线安装，好处是：安装方式简单，不易出错；源码包 安装是先将 nginx 的源码下载下来，在自己的系统里编译生成可执行文件，然后执行，好处是：因为是在自己的系统上编译的，更符合自己系统的性能，也就是说在自己的系统上执行 nginx 服务性能效率更好。 安装路径不同他们之间最大的区别是 ：安装位置不同。">
<meta name="twitter:image" content="https://segmentfault.com/img/bVD1yy?w=1316&h=440">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://blog.xiezc.xyz/2018/11/02/nginx_tomcat_jetty/centos安装nginx教程/">





  <title>centos安装nginx教程 | xiezc的小站</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ae02d8cf311eabbae2621ff2d51a260";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">xiezc的小站</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">xiezc的小站</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.xiezc.xyz/2018/11/02/nginx_tomcat_jetty/centos安装nginx教程/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="xiezc">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="xiezc的小站">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">centos安装nginx教程</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-02T14:54:03+08:00">
                2018-11-02
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/11/02/nginx_tomcat_jetty/centos安装nginx教程/" class="leancloud_visitors" data-flag-title="centos安装nginx教程">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="yum-和-源码包-安装的-区别"><a href="#yum-和-源码包-安装的-区别" class="headerlink" title="yum 和 源码包 安装的 区别"></a>yum 和 源码包 安装的 区别</h2><p>这里先说明下 <code>yum</code> 和 <code>源码包</code> 安装的 区别：</p>
<p><code>yum</code> 安装是在线安装，好处是：安装方式简单，不易出错；<br><code>源码包</code> 安装是先将 <code>nginx</code> 的源码下载下来，在自己的系统里编译生成可执行文件，然后执行，好处是：因为是在自己的系统上编译的，更符合自己系统的性能，也就是说在自己的系统上执行 <code>nginx</code> 服务性能效率更好。</p>
<h3 id="安装路径不同"><a href="#安装路径不同" class="headerlink" title="安装路径不同"></a>安装路径不同</h3><p>他们之间最大的区别是 ：<code>安装位置不同</code>。</p>
<p><code>yum</code> 在线安装会将 <code>nginx</code> 的安装文件放在系统的不同位置，可以通过命令 <code>rpm -ql nginx</code> 来查看安装路径，如下所示：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ rpm -ql nginx</span><br><span class="line">/etc/logrotate.d/nginx</span><br><span class="line">/etc/nginx</span><br><span class="line">/etc/nginx/conf.d</span><br><span class="line">/etc/nginx/conf.d/default.conf</span><br><span class="line">/etc/nginx/conf.d/ssl.conf</span><br><span class="line">/etc/nginx/conf.d/virtual.conf</span><br><span class="line">/etc/nginx/fastcgi.conf</span><br><span class="line">/etc/nginx/fastcgi.conf.default</span><br><span class="line">/etc/nginx/fastcgi_params</span><br><span class="line">/etc/nginx/fastcgi_params.default</span><br><span class="line">/etc/nginx/koi-utf</span><br><span class="line">/etc/nginx/koi-win</span><br><span class="line">/etc/nginx/mime.types</span><br><span class="line">/etc/nginx/mime.types.default</span><br><span class="line">/etc/nginx/nginx.conf</span><br><span class="line">/etc/nginx/nginx.conf.default</span><br><span class="line">/etc/nginx/scgi_params</span><br><span class="line">/etc/nginx/scgi_params.default</span><br><span class="line">/etc/nginx/uwsgi_params</span><br><span class="line">/etc/nginx/uwsgi_params.default</span><br><span class="line">/etc/nginx/win-utf</span><br><span class="line">/etc/rc.d/init.d/nginx</span><br><span class="line">/etc/sysconfig/nginx</span><br><span class="line">/usr/lib/perl5/vendor_perl/auto/nginx</span><br><span class="line">/usr/lib/perl5/vendor_perl/auto/nginx/nginx.so</span><br><span class="line">/usr/lib/perl5/vendor_perl/nginx.pm</span><br><span class="line">/usr/sbin/nginx</span><br><span class="line">/usr/share/doc/nginx-1.0.15</span><br><span class="line">/usr/share/doc/nginx-1.0.15/CHANGES</span><br><span class="line">/usr/share/doc/nginx-1.0.15/LICENSE</span><br><span class="line">/usr/share/doc/nginx-1.0.15/README</span><br><span class="line">/usr/share/man/man3/nginx.3pm.gz</span><br><span class="line">/usr/share/man/man8/nginx.8.gz</span><br><span class="line">/usr/share/nginx/html/404.html</span><br><span class="line">/usr/share/nginx/html/50x.html</span><br><span class="line">/usr/share/nginx/html/index.html</span><br><span class="line">/usr/share/nginx/html/nginx-logo.png</span><br><span class="line">/usr/share/nginx/html/poweredby.png</span><br><span class="line">/usr/share/vim/vimfiles/ftdetect/nginx.vim</span><br><span class="line">/usr/share/vim/vimfiles/indent/nginx.vim</span><br><span class="line">/usr/share/vim/vimfiles/syntax/nginx.vim</span><br><span class="line">/var/lib/nginx</span><br><span class="line">/var/lib/nginx/tmp</span><br><span class="line">/var/log/nginx</span><br></pre></td></tr></table></figure>
<p>卸载的时候，只能通过 命令来卸载，因为我们不可能 将这些文件自己手动删除，可以通过命令 <code>rpm -e nginx</code> 来卸载，这个命令一般不会报错，因为 <code>nginx</code> 不与其他的包有依赖关系，如果提示关于 依赖包的问题 ，可以尝试 <code>rpm -e --nodeps nginx</code> 来卸载，这个命令相当于强制卸载，不考虑依赖问题。</p>
<p><code>源码包</code> 安装他的所有文件（包括配置文件，库文件，资源文件等）都在同一个目录下，我们想卸载的时候，直接将这个文件删除就可以，不会有任何垃圾文件存在。<br>通过<code>源码包</code>编译安装的软件，通常都放在 <code>/usr/local/包名</code> 路径下。</p>
<h3 id="启动方式不同"><a href="#启动方式不同" class="headerlink" title="启动方式不同"></a>启动方式不同</h3><p><code>yum</code> 安装 <code>nginx</code>，我们可以通过 系统服务命令 <code>service</code> 来启动或停止</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">service nginx start #启动 nginx 服务</span><br><span class="line"></span><br><span class="line">service nginx stop #停止 nginx 服务</span><br><span class="line"></span><br><span class="line">service nginx restart #重启 nginx 服务</span><br></pre></td></tr></table></figure>
<p><code>源码包</code> 安装 <code>nginx</code> 启动的时候不能使用 <code>service</code> 来启动，需要执行 <code>nginx</code> 安装目录下的 <code>sbin</code> 目录下的 <code>nginx</code> 可执行程序才行，如下（我的 <code>nginx</code> 安装在 <code>/usr/local/webserver/</code> 目录下）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ /usr/local/webserver/nginx/sbin/nginx           #启动 nginx 服务</span><br><span class="line">➜  ~ /usr/local/webserver/nginx/sbin/nginx -s stop   #停止 nginx 服务</span><br></pre></td></tr></table></figure>
<p>或者 直接进入安装目录 ，执行 <code>./nginx</code> 也可以，这两种方式其实是一样的，<code>.</code> 表示当前目录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ cd /usr/local/webserver/nginx/sbin </span><br><span class="line">➜  sbin ls</span><br><span class="line">nginx</span><br><span class="line">➜  sbin ./nginx           #启动 nginx 服务</span><br><span class="line">➜  sbin ./nginx -s stop   #停止 nginx 服务</span><br></pre></td></tr></table></figure>
<p><code>注意：在自己的系统中只用选择一种安装方式即可，yum 安装的 nginx 版本可能不是最新的，可以通过 源码包 安装最新的，但系统中只要一种就可以，如果你想安装两个安装也可以，但是他们监听的端口都是 80 端口，每次只能启动一个</code></p>
<p>好，先讲了区别，下面来看一下安装方式</p>
<h2 id="yum-安装-nginx"><a href="#yum-安装-nginx" class="headerlink" title="yum 安装 nginx"></a>yum 安装 nginx</h2><h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><p>使用 <code>yum</code> 安装是在线安装，直接使用命令 <code>yum -y install nginx</code> 安装即可</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ yum -y install nginx</span><br><span class="line">已加载插件：fastestmirror, security</span><br><span class="line">设置安装进程</span><br><span class="line">Loading mirror speeds from cached hostfile</span><br><span class="line">解决依赖关系</span><br><span class="line">--&gt; 执行事务检查</span><br><span class="line">---&gt; Package nginx.i686 0:1.0.15-12.el6 will be 安装</span><br><span class="line">--&gt; 完成依赖关系计算</span><br><span class="line"></span><br><span class="line">依赖关系解决</span><br><span class="line"></span><br><span class="line">========================================================================================================================================</span><br><span class="line"> 软件包                        架构                         版本                                     仓库                          大小</span><br><span class="line">========================================================================================================================================</span><br><span class="line">正在安装:</span><br><span class="line"> nginx                         i686                         1.0.15-12.el6                            epel                         410 k</span><br><span class="line"></span><br><span class="line">事务概要</span><br><span class="line">========================================================================================================================================</span><br><span class="line">Install       1 Package(s)</span><br><span class="line"></span><br><span class="line">总下载量：410 k</span><br><span class="line">Installed size: 1.1 M</span><br><span class="line">下载软件包：</span><br><span class="line">nginx-1.0.15-12.el6.i686.rpm                                                                                     | 410 kB     00:00     </span><br><span class="line">运行 rpm_check_debug </span><br><span class="line">执行事务测试</span><br><span class="line">事务测试成功</span><br><span class="line">执行事务</span><br><span class="line">Warning: RPMDB altered outside of yum.</span><br><span class="line">  正在安装   : nginx-1.0.15-12.el6.i686                                                                                             1/1 </span><br><span class="line">  Verifying  : nginx-1.0.15-12.el6.i686                                                                                             1/1 </span><br><span class="line"></span><br><span class="line">已安装:</span><br><span class="line">  nginx.i686 0:1.0.15-12.el6                                                                                                            </span><br><span class="line"></span><br><span class="line">完毕！</span><br></pre></td></tr></table></figure>
<p>到这里就安装完成了，是不是很简单。</p>
<h3 id="启动-nginx-服务"><a href="#启动-nginx-服务" class="headerlink" title="启动 nginx 服务"></a>启动 nginx 服务</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ service nginx start</span><br><span class="line">Starting nginx:                                            [  OK  ]</span><br></pre></td></tr></table></figure>
<h3 id="停止-nginx-服务"><a href="#停止-nginx-服务" class="headerlink" title="停止 nginx 服务"></a>停止 nginx 服务</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ service nginx stop </span><br><span class="line">Stopping nginx:                                            [  OK  ]</span><br></pre></td></tr></table></figure>
<h3 id="重启-nginx-服务"><a href="#重启-nginx-服务" class="headerlink" title="重启 nginx 服务"></a>重启 nginx 服务</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ service nginx restart</span><br><span class="line">Stopping nginx:                                            [  OK  ]</span><br><span class="line">Starting nginx:                                            [  OK  ]</span><br></pre></td></tr></table></figure>
<p>启动后 ，在浏览器中 输入服务器的 ip 地址，就可以看到</p>
<p><img src="https://segmentfault.com/img/bVD1yy?w=1316&amp;h=440" alt="图片描述"></p>
<p>到这里 <code>yum</code> 安装 <code>nginx</code> 就完成了</p>
<h2 id="源码包-安装-nginx"><a href="#源码包-安装-nginx" class="headerlink" title="源码包 安装 nginx"></a>源码包 安装 nginx</h2><h3 id="安装编译"><a href="#安装编译" class="headerlink" title="安装编译"></a>安装编译</h3><p>我的系统 <code>centos 6.7 32位</code>，首先安装缺少的依赖包：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel</span><br></pre></td></tr></table></figure>
<p>从 <a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">http://nginx.org/en/download….</a> 下载稳定版 nginx-1.10.1.tar.gz ，下载的压缩文件 放在任意地方都可以，但是建议放在 <code>/usr/local/src</code> 或者 <code>/root/</code> 下，<code>/usr/local/src</code> 就是系统专门给用户分配的放 源码的目录，<code>/root/</code> 是我们默认操作的目录，所以也可以放在这里。我就是下载放在 <code>/root/</code> 目录下的。</p>
<p>下载可以通过命令获取：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://nginx.org/download/nginx-1.10.1.tar.gz</span><br></pre></td></tr></table></figure>
<p>解压缩：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf nginx-1.10.1.tar.gz</span><br></pre></td></tr></table></figure>
<p>解压缩后，可以看到 <code>nginx-1.10.1</code> 目录，然后进入这个目录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ ls</span><br><span class="line">anaconda-ks.cfg  install.log  install.log.syslog  nginx-1.10.1  nginx-1.10.1.tar.gz </span><br><span class="line">➜  ~ cd nginx-1.10.1</span><br></pre></td></tr></table></figure>
<p>在 <code>nginx-1.10.1</code>目录下执行 配置 和 make 命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">➜  nginx-1.10.1 ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre</span><br><span class="line"></span><br><span class="line">➜  nginx-1.10.1 make &amp;&amp; make install</span><br></pre></td></tr></table></figure>
<h4 id="常用编译选项说明"><a href="#常用编译选项说明" class="headerlink" title="常用编译选项说明"></a>常用编译选项说明</h4><p>这段说明，参考自：<a href="https://segmentfault.com/a/1190000002797601" target="_blank" rel="noopener">https://segmentfault.com/a/11…</a></p>
<ul>
<li><code>--prefix=PATH</code> ： 指定 <code>nginx</code> 的安装目录。默认 <code>/usr/local/nginx</code>，我的是 <code>/usr/local/webserver/nginx</code></li>
<li><code>--conf-path=PATH</code> ： 设置<code>nginx.conf</code>配置文件的路径。<code>nginx</code>允许使用不同的配置文件启动，通过命令行中的<code>-c</code>选项。默认为<code>conf/nginx.conf</code></li>
<li><code>--user=name</code> ： 设置<code>nginx</code>工作进程的用户。安装完成后，可以随时在<code>nginx.conf</code>配置文件更改<code>user</code>指令。默认的用户名是<code>nobody</code>。<code>--group=name</code>类似</li>
<li><code>--with-pcre</code> ： 设置PCRE库的源码路径，如果已通过yum方式安装，使用–with-pcre自动找到库文件。使用<code>--with-pcre=PATH</code>时，需要从PCRE网站下载pcre库的源码（8.39）并解压，指定 <code>pcre</code> 的源码路径 ，比如：<code>--with-pcre=/root/pcre-8.39/</code>。perl正则表达式使用在<code>location</code>指令和 <code>ngx_http_rewrite_module</code>模块中。</li>
<li><code>--with-zlib=PATH</code> ： 指定 <code>zlib</code>（版本1.1.3 - 1.2.5）的源码解压目录。在默认就启用的网络传输压缩模块<code>ngx_http_gzip_module</code>时需要使用zlib 。</li>
<li><code>--with-http_ssl_module</code> ： 使用<code>https</code>协议模块。默认情况下，该模块没有被构建。前提是<code>openssl</code>与<code>openssl-devel</code>已安装</li>
<li><code>--with-http_stub_status_module</code> ： 用来监控 <code>Nginx</code> 的当前状态</li>
<li><code>--with-http_realip_module</code> ： 通过这个模块允许我们改变客户端请求头中客户端<code>IP</code>地址值(例如<code>X-Real-IP</code> 或 <code>X-Forwarded-For</code>)，意义在于能够使得后台服务器记录原始客户端的<code>IP</code>地址</li>
<li><code>--add-module=PATH</code> ： 添加第三方外部模块，如<code>nginx-sticky-module-ng</code>或缓存模块。每次添加新的模块都要重新编译（<code>Tengine</code>可以在新加入<code>module</code>时无需重新编译）</li>
</ul>
<h3 id="启动-停止-nginx"><a href="#启动-停止-nginx" class="headerlink" title="启动 停止 nginx"></a>启动 停止 nginx</h3><p>使用 <code>源码包</code> 安装 <code>nginx</code> ，启动时需要使用绝对路径来执行，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ /usr/local/webserver/nginx/sbin/nginx           #启动 nginx 服务</span><br><span class="line">➜  ~ /usr/local/webserver/nginx/sbin/nginx -s stop   #停止 nginx 服务</span><br></pre></td></tr></table></figure>
<p>启动 <code>nginx</code> 服务后，可以通过 <code>ps -aux | grep nginx</code> 查看进程</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">➜  ~ /usr/local/webserver/nginx/sbin/nginx           #启动 nginx 服务</span><br><span class="line">➜  ~ ps -aux | grep nginx</span><br><span class="line">Warning: bad syntax, perhaps a bogus &apos;-&apos;? See /usr/share/doc/procps-3.2.8/FAQ</span><br><span class="line">root      9628  0.0  0.1  15292  1500 ?        Ss   11:17   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf</span><br><span class="line">nginx     9631  0.0  0.2  15448  2312 ?        S    11:17   0:00 nginx: worker process                   </span><br><span class="line">root     13158  0.0  0.0   6048   788 pts/1    S+   12:12   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx</span><br></pre></td></tr></table></figure>
<p>启动后 ，在浏览器中 输入服务器的 ip 地址，就可以看到</p>
<p><img src="https://segmentfault.com/img/bVD1yj?w=650&amp;h=261" alt="图片描述"></p>
<p>到这里 <code>源码包</code> 安装 <code>nginx</code> 就完成了</p>
<p>可以看出 两个欢迎页面是不同的，这个主要是版本不同的原因。</p>
<h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><blockquote>
<p>这里讲了 使用 <code>yum</code> 和 <code>源码包</code> 安装 <code>nginx</code> 的详细过程，如果想了解 <code>yum</code> 和 <code>源码包</code> 安装软件的其他详细知识，可以看我的另外一篇博文 <a href="https://segmentfault.com/a/1190000007109304" target="_blank" rel="noopener">《Linux 软件安装管理》</a>。</p>
<p>本文中如有纰漏，或者你有什么问题，都可以提出来，谢谢～～</p>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/linux/" rel="tag"># linux</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/11/02/docker/docker设置容器的时区/" rel="next" title="Docker 中如何设置 container 的时区">
                <i class="fa fa-chevron-left"></i> Docker 中如何设置 container 的时区
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/11/02/docker/docker安装nextcloud教程/" rel="prev" title="Nextcloud docker 安装教程">
                Nextcloud docker 安装教程 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">xiezc</p>
              <p class="site-description motion-element" itemprop="description">主要一些技术文章, 有些文章是转载的</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">72</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">分类</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">20</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#yum-和-源码包-安装的-区别"><span class="nav-number">1.</span> <span class="nav-text">yum 和 源码包 安装的 区别</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装路径不同"><span class="nav-number">1.1.</span> <span class="nav-text">安装路径不同</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动方式不同"><span class="nav-number">1.2.</span> <span class="nav-text">启动方式不同</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#yum-安装-nginx"><span class="nav-number">2.</span> <span class="nav-text">yum 安装 nginx</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装"><span class="nav-number">2.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动-nginx-服务"><span class="nav-number">2.2.</span> <span class="nav-text">启动 nginx 服务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#停止-nginx-服务"><span class="nav-number">2.3.</span> <span class="nav-text">停止 nginx 服务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重启-nginx-服务"><span class="nav-number">2.4.</span> <span class="nav-text">重启 nginx 服务</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#源码包-安装-nginx"><span class="nav-number">3.</span> <span class="nav-text">源码包 安装 nginx</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装编译"><span class="nav-number">3.1.</span> <span class="nav-text">安装编译</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常用编译选项说明"><span class="nav-number">3.1.1.</span> <span class="nav-text">常用编译选项说明</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动-停止-nginx"><span class="nav-number">3.2.</span> <span class="nav-text">启动 停止 nginx</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结语"><span class="nav-number">4.</span> <span class="nav-text">结语</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xiezc</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("eRAHvO0xVYwckgdXIVpfugRG-gzGzoHsz", "57lKp708hde92YeG1xX9MQj1");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

</body>
</html>
